﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model.Util;
using Xproject.Framework.Core.Repositories;
using Xproject.Framework.Utility.Extensions;

namespace Repository.Util
{
    public static class UploadFileRep
    {
        public static UploadFile Get(this IRepositoryAsync<UploadFile> repository, string site,string  fileId)
        {
            Expression<Func<UploadFile, bool>> express = i => i.Site == site;
            if (!string.IsNullOrEmpty(fileId ))
            {
                express = express.AndAlso(i => fileId== i.FileId);
            }
            return repository.Query().Where(express).Select().FirstOrDefault();
        }

        public static List<UploadFile> GetUploadFiles(this IRepositoryAsync<UploadFile> repository,string site, List<string> fileIds)
        {
            Expression<Func<UploadFile, bool>> express = i => i.Site == site;
            if (fileIds != null && fileIds.Count > 0)
            {
                express = express.AndAlso(i => fileIds.Contains(i.FileId));
            } 
            return repository.Query().Where(express).Select().OrderByDescending(i => i.CreateTime).ToList();
        }
    }
}
